// demo4_stream_split_lines.js

var through = require('through2');
var split = require('split2');
const fs = require('fs-extra');

var lineCount = 0;
var transform = through(function (buf, _, next) {
    var line = buf.toString();
    this.push(lineCount % 2 === 0
        ? line.toLowerCase() + '\n'
        : line.toUpperCase() + '\n'
    );
    lineCount++;
    next();
});

//process.stdin
fs.createReadStream('./finnegans_wake.txt')
    .pipe(split())
    .pipe(transform)
    .pipe(process.stdout)
    ;
